import urllib
import urllib2
import json

server = 'http://localhost:8888'
#server = 'http://hdc1112.appspot.com'
url = server+'/login'
data = urllib2.urlopen(url).read()
user = json.read(data)['sessionID']

import time
import threading
sessionID= user
class Timer(threading.Thread):
	global sessionID
	def __init__(self, seconds):
		self.runTime = seconds
		threading.Thread.__init__(self)
	def run(self):
		time.sleep(self.runTime)
		url = server+'/getNotification?sessionID='+sessionID
		data = urllib2.urlopen(url).read()
		print data
		Timer(3).start();
t = Timer(3)
t.start()

while True :   
	entry = raw_input('>')
	url = server+'/addChat?sessionID='+sessionID+'&content='+entry
	data = urllib2.urlopen(url).read()

'''
#print 'request:',url
#print 'response:',data
u1 = json.read(data)['sessionID']
print u1

url = server+'/addChat?sessionID='+u1+"&content=abc"
data = urllib2.urlopen(url).read();
print 'request:',url
print 'response:',data

#user 2 login:
url = server+'/login'
data = urllib2.urlopen(url).read()
print 'request:',url
print 'response:',data
u2 = json.read(data)['sessionID']
print u2

url = server+'/getNotification?sessionID='+u2
data = urllib2.urlopen(url).read()
print 'request:',url
print 'response:',data
#user2 send
url = server+'/addChat?sessionID='+u2+"&content=def"
data = urllib2.urlopen(url).read();
print 'request:',url
print 'response:',data
#user2 send
url = server+'/addChat?sessionID='+u2+"&content=ghi"
data = urllib2.urlopen(url).read();
print 'request:',url
print 'response:',data


#user 3 login
url = server+'/login'
data = urllib2.urlopen(url).read()
print 'request:',url
print 'response:',data

u3 = json.read(data)['sessionID']
print u3

url = server+'/getNotification?sessionID='+u3
data = urllib2.urlopen(url).read()
print 'request:',url
print 'response:',data

'''